#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int INF = 1 << 30;
const ldb pi = fabsl(atan2(0.0, -1.0));
using namespace std;

char s[200050];
int n, k, m;
int af[200050][27], bef[200050][27];

void Load()
{
	cin >> k >> n;
	nextLine();
	gets(s);
	m = n;
	int i;
	int j;
	for (j = 0; j < 26; j++)
	{
		bef[0][j] = af[m - 1][j] = -1;
	}
	for (i = 0; i < m; i++)
	{
		if (i > 0)
		{
			for (j = 0; j < 26; j++)
			{
				bef[i][j] = bef[i - 1][j];
			}
		}
		bef[i][s[i] - 'a'] = i; 
	}
	for (i = m - 1; i >= 0; i--)
	{
		if (i + 1 < m)
		{
			for (j = 0; j < 26; j++)
			{
				af[i][j] = af[i + 1][j];
			}
		}
		af[i][s[i] - 'a'] = i; 
	}
	for (i = m; i <= 200000; i++)
	{
		for (j = 0; j < 26; j++)
		{
			bef[i][j] = bef[i - 1][j];
			af[i][j] = -1;
		}
	}

}
void Solve()
{
	int i;
	int j;
	for (i = 0; i < k; i++)
	{
		gets(s);
		LL score = 0;
		int t;
		m = strlen(s);
		for (j = 0; s[j] != 0; j++)
		{
			t = INF;
			if (bef[j][s[j] - 'a'] != -1) t = min(abs(j - bef[j][s[j] - 'a']), t);
			if (af[j][s[j] - 'a'] != -1) t = min(abs(j - af[j][s[j] - 'a']), t);
			if (t == INF) score += (LL)m;
			else score += (LL)t;
		}
		printf("%I64d\n", score);
	}
}

#define file "b"
int main()
{
	#ifndef ONLINE_JUDGE
	freopen(file".in", "rt", stdin);
	freopen(file".out", "wt", stdout);
	#endif
	Load();
	Solve();
	return 0;
}